import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
    //是否登录
		hasLogin: uni.getStorageSync("hasLogin"),
    //用户信息
		userInfo: uni.getStorageSync("userInfo"),
	},
	mutations: {
    /** 
     * 登录成功
     * @param {Object} userInfo 用户信息
     */
		login(userInfo,state) {
      state.userInfo = userInfo;
			state.hasLogin = true;
			uni.setStorageSync("userInfo", userInfo);
			uni.setStorageSync("hasLogin", true);
		},
    /**
     * 退出登录
     */
		logout(state) {
			state.hasLogin = false;
			state.userInfo = null;
			uni.removeStorageSync("hasLogin");
			uni.removeStorageSync("userInfo");
		}
	}
})

export default store